package com.intellagric.controller.module.trace_produce_batch;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.module.traceability.ProduceBatchVo;
import com.intellagric.pojo.TraceProduceBatch;
import com.intellagric.service.traceability.trace_produce_batch.ProduceBatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/11/6
 * @DESC： 产品批次信息管理
 */
@Controller
public class ProduceBatchControler {

    @Autowired
    private ProduceBatchService produceBatchService;

    /**
     * 添加产品批次信息
     * @Param 
     * @return ResponseMessage
     */
    @RequestMapping("/produce/batch/add")
    @ResponseBody
    public ResponseMessage add(TraceProduceBatch produceBatch) {
        //初始化
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String id = dateFormat.format(new Date());
        produceBatch.setId(id);
        produceBatch.setCreateDate(new Date());
        produceBatch.setUpdateDate(new Date());
        return produceBatchService.addProduceBatch(produceBatch);
    }

    /**
     * 删除产品批次信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/produce/batch/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return produceBatchService.deleteProduceBatch(id);
    }
    
    /**
     * 修改产品批次信息
     * @Param produceBatch
     * @return ResponseMessage
     */
    @RequestMapping("/produce/batch/edit")
    @ResponseBody
    public ResponseMessage edit(TraceProduceBatch produceBatch) {
        produceBatch.setUpdateDate(new Date());
        produceBatch.setCreateDate(null);
        return produceBatchService.editProduceBatch(produceBatch);
    }
    
    /**
     * 查询产品批次信息
     * @return TraceProduceBatch
     */
    @RequestMapping("/produce/batch/{id}")
    @ResponseBody
    public TraceProduceBatch get(@PathVariable String id) {
        return produceBatchService.getProduceBatchById(id);
    }
    
    /**
     * 查询产品批次信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/produce/batch/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return produceBatchService.getProduceBatchList();
    }
    @RequestMapping("/produce/batch/listByCreateBy")
    @ResponseBody
    public LayuiDataGridResult getList(String createBy) {
        return produceBatchService.getProduceBatchList(createBy);
    }

    /**
     * 根据批次号进行产品的溯源，查询产品批次信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/produce/trace/list")
    @ResponseBody
    public LayuiDataGridResult getTraceList(int page ,int limit,ProduceBatchVo produceBatchVo) {
        return produceBatchService.getProduceBatchListWithRelation(page, limit, produceBatchVo);
    }
    
    /**
     * 分页查询产品批次信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/produce/batch/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page ,int limit) {
        return produceBatchService.getProduceBatchPage(page,limit);
    }
    /**
     * 分页查询产品批次信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/produce/batch/pageByCreateBy")
    @ResponseBody
    public LayuiDataGridResult getPage(int page ,int limit,String createBy) {
        return produceBatchService.getProduceBatchPage(page,limit,createBy);
    }

    /**
     * 根据VO实体类查询产品批次信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/produce/batch/query")
    @ResponseBody
    public LayuiDataGridResult getByVo(int page ,int limit,ProduceBatchVo produceBatchVo) {
        return produceBatchService.getProduceBatchByVo(page, limit, produceBatchVo);
    }
}
